package net.zjitc.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/9/25.
 */
@WebServlet(name = "LoginServlet",urlPatterns = "/loginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          //修改请求的编码方式
            request.setCharacterEncoding("utf-8");
            String username = request.getParameter("user");
            String password= request.getParameter("pass");


            System.out.println(username );
            System.out.println(password);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("user");
        String password= request.getParameter("pass");
        /**
         * 假如出现乱码，添加以下一句话：用于字符串的重新编码
         * username  8859的编码方式---utf-8
         *
         * */
        username = new String(username.getBytes("iso8859-1"),"utf-8");

        System.out.println("get......");
        System.out.println(username );
        System.out.println(password);
    }
}
